package com.inexas.cu.stratus;

import java.util.*;
import com.google.inject.*;

// ?todo Can I restrict T to extends BigTableEntity?
@ImplementedBy(BigtableStratus.class)
public interface Stratus {
	/**
	 * Create (persist) the object to Bigtable
	 * 
	 * @param entity
	 */
	void create(Entity entity);
	
	/**
	 * Get object by it's primary key (ident)
	 * 
	 * @param type the type of the entity, e.g. Person.class
	 * @param ident the primary key of the entity
	 * @return the chosen entity or null if not found
	 */
	<T> T findByIdent(Class<T> type, Long ident);

	/**
	 * Get the extent
	 */
	<T> Iterator<T> findAll(Class<T> type); 
	
	/**
	 * Retrieve a single object according to some constraints. The constraints
	 * is a list of at least one string in the form "fname:value" or "fname"
	 * where fname is a field name and value is what it should be equal to as 
	 * a string. If there is no value then the fnames are used to order the
	 * result set. When the fname appears by itself then it may be appended
	 * by either '+' ascending or '-' descending.
	 * 
	 * Example: findBy(Customer.class, "firstName:Keith", "lastName-");
	 * 
	 * If there is more than one object matching then the first matching 
	 * entity is returned
	 * 
	 * @param type
	 * @param constraints
	 * @return
	 */
	<T> T findBy(Class<T> type, String... constraints); 

	
	/**
	 * Same as findBy() but returns all
	 * 
	 * @param type
	 * @param constraints
	 * @return
	 */
	<T> List<? extends T> findAllBy(Class<T> type, String... constraints);
	
	void update(Entity entity) throws NoSuchEntityException;
	
	void delete(Entity entity) throws NoSuchEntityException;

	void deleteAll(Class<? extends Entity> type);

}
